package com.wkk.nursinghome.service.impl;

import com.wkk.nursinghome.convert.Age;
import com.wkk.nursinghome.dao.IWithdrawalDao;
import com.wkk.nursinghome.domain.Checkin;
import com.wkk.nursinghome.domain.Withdrawal;
import com.wkk.nursinghome.service.IWithdrawalService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class WithdrawalServiceImpl implements IWithdrawalService {

    //注入对象
    @Resource
    private IWithdrawalDao withdrawalDao;

    //查询所有
    @Override
    public List<Withdrawal> selectAll() {
        List<Withdrawal> withdrawals=withdrawalDao.selectAll();
        for (Withdrawal withdrawal:withdrawals){
            String age=withdrawal.getAge();
            age= Age.getPersonAgeByBirthDate(age);
            withdrawal.setAge(age);
        }
        return withdrawals;
    }

    //增加
    @Override
    public void addWithdrawal(Withdrawal withdrawal) {
        withdrawalDao.insertWithdrawal(withdrawal);
    }

    //修改
    @Override
    public boolean updateWithdrawal(Withdrawal withdrawal) {
        return withdrawalDao.updateWithdrawal(withdrawal) > 0;
    }

    //按id查询
    @Override
    public Withdrawal queryById(Integer id) {
        return withdrawalDao.selectById(id);
    }

    //删除信息
    @Override
    public boolean deleteWithdrawalById(Integer id) {
        return withdrawalDao.deleteWithdrawalById(id) > 0;
    }


    //按条件查询
    @Override
    public List<Withdrawal> selectByCondition(Withdrawal withdrawal) {
        List<Withdrawal> withdrawals=withdrawalDao.getWithdrawalByCondition(withdrawal);
        for (Withdrawal withdrawal1:withdrawals){
            String age=withdrawal1.getAge();
            age= Age.getPersonAgeByBirthDate(age);
            withdrawal1.setAge(age);
        }
        return withdrawals;
    }
}
